-
Notifications
You must be signed in to change notification settings - Fork 324
Align y-axes in mmm.plot.budget_allocation #1967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Align y-axes in mmm.plot.budget_allocation #1967
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1967 +/- ##
==========================================
- Coverage 92.18% 91.94% -0.24%
==========================================
Files 67 67
Lines 8147 8169 +22
==========================================
+ Hits 7510 7511 +1
- Misses 637 658 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
still needs tests to go through the combinations of negative positive and ensure that the axis limits are correct after the call. |
if ax.axes.get_ylim()[0] < 0 or ax2.axes.get_ylim()[0] < 0: | ||
ylims1 = ax.axes.get_ylim() | ||
ylims2 = ax2.axes.get_ylim() | ||
# Find the ratio of negative vs. positive part of the axes. | ||
if ylims1[1]: | ||
ax1_yratio = ylims1[0] / ylims1[1] | ||
else: | ||
# Fully negative axis. | ||
ax1_yratio = -1 | ||
|
||
if ylims2[1]: | ||
ax2_yratio = ylims2[0] / ylims2[1] | ||
else: | ||
# Fully negative axis, may need to reflect the other | ||
ax2_yratio = -1 | ||
|
||
# Make axis adjustments. If both axes fully negative, no adjustment. | ||
if ax1_yratio < ax2_yratio: | ||
ax2.set_ylim(bottom=ylims2[1] * ax1_yratio) | ||
if ax1_yratio == -1: | ||
# if the axis is fully negative, center zero. | ||
ax.set_ylim(top=-ylims1[0]) | ||
elif ax2_yratio < ax1_yratio: | ||
ax.set_ylim(bottom=ylims1[1] * ax2_yratio) | ||
if ax2_yratio == -1: | ||
# if the axis is fully negative, center zero. | ||
ax2.set_ylim(top=-ylims2[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use NamedTuple or something. Quite confusing to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this now, I fully agree. I also think that this is not capturing every possible combination the axes can get odd. I'll move this to a draft and rework it.
Description
Ensure that y=0 is aligned between the primary and secondary y-axis in
mmm.plot.budget_allocation
.Solution
If one axis includes negative, values the other is extended down so that the y=0 is aligned.
If all contributions would be fully negative (I don't know when this would happen...), the y=0 level is centered vertically on both axes.
Related Issue
Checklist
pre-commit.ci autofix
to auto-fix.📚 Documentation preview 📚: https://pymc-marketing--1967.org.readthedocs.build/en/1967/